Fixed an issue where EXPLAIN and EXPLAIN ANALYZE not working if blank line is there in the SQL query.#9670
Fixed an issue where EXPLAIN and EXPLAIN ANALYZE not working if blank line is there in the SQL query.#9670akshay-joshi wants to merge 1 commit intopgadmin-org:masterfrom
Conversation
… line is there in the SQL query.
WalkthroughThe changes refactor query detection logic in CustomEditorView.js to properly handle blank lines and comments between SQL clauses. The Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js`:
- Around line 238-240: Clamp startPos to the document length as well as the
lower bound: after computing startPos (which can be set to currLine.to + 1 in
the codepath around where currLine is used), add an upper-bound check similar to
endPos so if startPos > this.state.doc.length set startPos =
this.state.doc.length; ensure you update the existing bounds block that
currently checks "if(startPos < 0) startPos = 0;" and "if(endPos >
this.state.doc.length) endPos = this.state.doc.length;" to include the startPos
upper clamp.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.jsweb/regression/javascript/components/CodeMirrorCustomEditor.spec.js
| // Make sure start and end are valid values | ||
| if(startPos < 0) startPos = 0; | ||
| if(endPos > this.state.doc.length) endPos = this.state.doc.length; |
There was a problem hiding this comment.
Clamp startPos to the document length.
Line 239 only guards the lower bound. startPos can become currLine.to + 1 (Line 151) on a trailing blank line, which can exceed doc.length and return an invalid from. Add an upper-bound clamp alongside the existing checks.
🛠️ Proposed fix
- if(startPos < 0) startPos = 0;
+ if(startPos < 0) startPos = 0;
+ if(startPos > this.state.doc.length) startPos = this.state.doc.length;
if(endPos > this.state.doc.length) endPos = this.state.doc.length;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Make sure start and end are valid values | |
| if(startPos < 0) startPos = 0; | |
| if(endPos > this.state.doc.length) endPos = this.state.doc.length; | |
| // Make sure start and end are valid values | |
| if(startPos < 0) startPos = 0; | |
| if(startPos > this.state.doc.length) startPos = this.state.doc.length; | |
| if(endPos > this.state.doc.length) endPos = this.state.doc.length; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js` around
lines 238 - 240, Clamp startPos to the document length as well as the lower
bound: after computing startPos (which can be set to currLine.to + 1 in the
codepath around where currLine is used), add an upper-bound check similar to
endPos so if startPos > this.state.doc.length set startPos =
this.state.doc.length; ensure you update the existing bounds block that
currently checks "if(startPos < 0) startPos = 0;" and "if(endPos >
this.state.doc.length) endPos = this.state.doc.length;" to include the startPos
upper clamp.
Summary by CodeRabbit
Bug Fixes
Tests